package com.wty.cmims.controller;

import com.wty.cmims.pojo.ResponseResult;
import com.wty.cmims.service.InstitutionMedicationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/institutionMedication")
@Tag(name = "医疗机构——药品信息", description = "社区医疗信息后台管理系统api接口")
public class InstitutionMedicationController {
    @Autowired
    private InstitutionMedicationService institutionMedicationService;

    // 医疗机构——药品信息获取
    @PostMapping("/findIMByInstitutionId")
    @Operation(summary = "医疗机构——药品信息获取", description = "医疗机构——药品信息获取")
    @Parameter(name = "paramsMap",description = "参数列表")
    @ApiResponse(description = "处理结果",content = {
            @Content(
                    mediaType="application/json",
                    schema= @Schema(implementation = ResponseResult.class)
            )
    })
    public ResponseResult<Map<String, Object>> findIMByInstitutionId(@RequestBody Map<String,Object> paramsMap){
        return institutionMedicationService.findIMByInstitutionId(paramsMap);
    }

    // 药品库存修改
    @PutMapping ("/updateIMStock")
    @Operation(summary = "药品库存修改", description = "药品库存修改")
    @Parameter(name = "paramsMap",description = "参数列表")
    @ApiResponse(description = "处理结果",content = {
            @Content(
                    mediaType="application/json",
                    schema= @Schema(implementation = ResponseResult.class)
            )
    })
    public ResponseResult<Void> updateIMStock(@RequestBody Map<String,Object> paramsMap){
        return institutionMedicationService.updateIMStock(paramsMap);
    }

    // 医疗机构药品添加
    @PostMapping("/addIM")
    @Operation(summary = "医疗机构药品添加", description = "医疗机构药品添加")
    @Parameter(name = "paramsMap",description = "参数列表")
    @ApiResponse(description = "处理结果",content = {
            @Content(
                    mediaType="application/json",
                    schema= @Schema(implementation = ResponseResult.class)
            )
    })
    public ResponseResult<Void> addIM(@RequestBody Map<String,Object> paramsMap){
        return institutionMedicationService.addIM(paramsMap);
    }

    // 医疗机构药品删除
    @PutMapping("/deleteIM")
    @Operation(summary = "医疗机构药品删除", description = "医疗机构药品删除")
    @Parameter(name = "institution_id",description = "医疗机构ID")
    @Parameter(name = "medication_id",description = "药品ID")
    @ApiResponse(description = "处理结果",content = {
            @Content(
                    mediaType="application/json",
                    schema= @Schema(implementation = ResponseResult.class)
            )
    })
    public ResponseResult<Void> deleteIM(@RequestParam Integer institution_id,@RequestParam Integer medication_id){
        return institutionMedicationService.deleteIM(institution_id,medication_id);
   }
}